package me.riverslob;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class BatchDownload {
    public static void main(String[] args) throws Exception {
        System.out.println("in BatchDownload................");
        File outFile = new File("D:/test.zip");
        FileOutputStream outputStream= new FileOutputStream(outFile);
        ZipOutputStream zos = new ZipOutputStream(outputStream);
        File[] files = new File[11];
        files[10]=new File("http://10.100.20.160//upload/vehicle/crash/2013/05/15/VC201305151024551.jpg");
//        files[0]=new File("D:/OptiCM-POC/KDKK3Project/KDKK/images/1.jpg");
//        files[1]=new File("D:/OptiCM-POC/KDKK3Project/KDKK/images/2.jpg");
        zipFile(files, "", zos);
        zos.flush();
        zos.close();
    }

    private static void zipFile(File[] subs, String baseName, ZipOutputStream zos) throws IOException {
        for (int i=0;i<subs.length;i++) {
            File f=subs[i];
            zos.putNextEntry(new ZipEntry(baseName + f.getName()));
            FileInputStream fis = new FileInputStream(f);
            byte[] buffer = new byte[1024];
            int r = 0;
            while ((r = fis.read(buffer)) != -1) {
                zos.write(buffer, 0, r);
            }
            fis.close();
        }
    }
}
